package leetcode;

import java.util.Arrays;

public class LeetCodeMain117 {
    public int translateNum(int num) {
        String str=String.valueOf(num);
        int length=str.length();
        int[] dp=new int[length+1];
        dp[0]=1;
        dp[1]=1;
        for (int i = 2; i <= length; i++) {
            char ch1=str.charAt(i-2);
            char ch2=str.charAt(i-1);
            int sum=(ch1-'0')*10+(ch2-'0');
            if (sum>=10&&sum<=25){
                dp[i]=dp[i-2]+dp[i-1];
            }else {
                dp[i]=dp[i-1];
            }
        }
        return dp[length];
    }
    public int maxProfit(int[] prices) {
        if (prices==null||prices.length==0){
            return 0;
        }
        int length=prices.length;
        int[][] dp=new int[length][2];
        dp[0][0]=-prices[0];
        dp[0][1]=0;
        int max=0;
        for (int i = 1; i < length; i++) {
            dp[i][0]=Math.max(dp[i-1][0],-prices[i]);
            dp[i][1]=Math.max(dp[i-1][1],prices[i]+dp[i-1][0]);
        }
        return dp[length-1][1];
    }
}
